package com.health.service.impl;

import com.health.entity.TRole;
import com.health.entity.pojo.vo.AdminVO;
import com.health.entity.pojo.vo.TRoleVO;
import com.health.mapper.TRoleMapper;
import com.health.service.ITRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sanchuan
 * @since 2023-04-20
 */
@Service
public class TRoleServiceImpl extends ServiceImpl<TRoleMapper, TRole> implements ITRoleService {

    @Autowired
    private TRoleMapper roleMapper;

    /**
     * 获得角色列表
     * @return
     */
    @Override
    public List<TRoleVO> listRoles() {
        List<TRoleVO> roleVOList = roleMapper.listRoles();
        for (TRoleVO roleVO: roleVOList) {
            roleVO.setNumbers(roleMapper.adminCount(roleVO.getId()));
        }
        return roleVOList;
    }

    /**
     * 获得后台管理人员列表
     * @param rid
     * @return
     */
    @Override
    public List<AdminVO> listAdmin(Integer rid) {
        return roleMapper.listAdmin(rid);
    }

    /**
     * 启用停用角色
     * @param isShelves
     * @param id
     * @return
     */
    @Override
    public Boolean updateShelves(Boolean isShelves, Integer id) {
        return roleMapper.updateShelves(isShelves,id);
    }

    /**
     * 根据部门id获得下属角色
     * @param departmentId
     * @return
     */
    @Override
    public List<TRoleVO> listRolesByDID(Integer departmentId) {
        return roleMapper.listRolesByDID(departmentId);
    }
}
